#!/bin/bash

set -e

####
## Functions
####

function enable_mod() {
    # This function runs the initial configuration the module needs once it is enabled for the first time

    # move out old amavis conf files
    mv /etc/amavis/conf.d /etc/amavis/conf.d.old
    mkdir -p /etc/amavis/conf.d
    chmod --reference=/etc/amavis/conf.d.old /etc/amavis/conf.d
    chown --reference=/etc/amavis/conf.d.old /etc/amavis/conf.d

    if ! groups clamav | grep -q amavis; then
      # add clamav user to group amavis. Because it need access to amavis stuff
      addgroup clamav amavis
    fi

    /usr/share/zentyal-mailfilter/create-spamassassin-db
}


####
## Calls
####

enable_mod

exit 0
